home *** CD-ROM | disk | FTP | other *** search
/ Aminet 30 / Aminet 30 (1999)(Schatztruhe)[!][Apr 1999].iso / Aminet / util / pack / xpk_Source.lha / xpk_Source / xpkmaster / progress.c < prev    next >
C/C++ Source or Header  |  1998-11-09  |  2KB  |  71 lines

  1. #ifndef XPKMASTER_PROGRESS_C
  2. #define XPKMASTER_PROGRESS_C
  3.  
  4. /* Routinesheader
  5.  
  6.     Name:        progress.c
  7.     Main:        xpkmaster
  8.     Versionstring:    $VER: progress.c 1.4 (26.03.1998)
  9.     Author:        SDI
  10.     Distribution:    Freeware
  11.     Description:    Progress report handler
  12.  
  13.  1.0   06.10.96 : first real version
  14.  1.1   24.03.97 : added auto hook, changed speed calculation
  15.  1.2   25.04.97 : changed time calculation
  16.  1.3   09.01.98 : added XPK_ALLINONE
  17.  1.4   26.03.98 : a bit shorter exe code
  18. */
  19.  
  20. #include <proto/exec.h>
  21. #include <proto/intuition.h>
  22. #include <xpk/xpkprefs.h>
  23. #include "xpkmaster.h"
  24.  
  25. XPK_ALLINONE LONG callprogress(struct XpkBuffer *xbuf)
  26. {
  27.   struct XpkProgress *prog = &xbuf->xb_Prog;
  28.   struct Hook *hk = xbuf->xb_ChunkHook;
  29.   struct XpkPrefsSemaphore *sem = 0;
  30.  
  31.   if(!hk && (xbuf->xb_Flags & XMF_AUTOPRHOOK) && (sem = GetPrefsSem()))
  32.     hk = sem->xps_ProgressHook;
  33.  
  34.   if(hk)
  35.   {
  36.     ULONG ucur, ulen;
  37.  
  38.     if((ucur = prog->xp_UCur) && (ulen = prog->xp_ULen))
  39.     {
  40.       ULONG secs;
  41.       LONG mics;
  42.  
  43.       CurrentTime (&secs, (ULONG *) &mics);
  44.       secs -= xbuf->xb_Secs;
  45.       mics -= xbuf->xb_Mics;
  46.  
  47.       /* 7813 = 100000 / 128, 0x20000000 = 0x100000000/128 (ULONG size),
  48.          +1 prevents division by zero */
  49.       if(ucur < 0x20000000)
  50.         prog->xp_Speed = (ucur<<7) / ((secs<<7) + mics/7813 + 1);
  51.       else
  52.         prog->xp_Speed = ucur / ++secs;
  53.  
  54.       prog->xp_Done = 100 * ucur/ulen;
  55.       prog->xp_CF = 100 - 100 * prog->xp_CCur / ucur;
  56.     }
  57.     if(prog->xp_CF < 0)
  58.       prog->xp_CF = 0;
  59.  
  60.     if((*(regfunc) hk->h_Entry) (hk, prog, 0 A4SUPP2))
  61.       xbuf->xb_Result = XPKERR_ABORTED;
  62.   }
  63.  
  64.   if(sem)
  65.     ReleaseSemaphore((struct SignalSemaphore *) sem);
  66.  
  67.   return xbuf->xb_Result;
  68. }
  69.  
  70. #endif /* XPKMASTER_PROGRESS_C */
  71.